
*------------------------------------------------------------------------------*
* Authors: 		Sabine C. Carey (University of Mannheim) and 
*				Juergen Brandsch (KfW Development Bank)
* Article: 		Borders and bullies: How borders shape perceptions of security and foreign policy preferences
* Journal: 		Research & Politics 
* Date: 		2024-01
* Instructions: This do file replicates probabilities graphs Figures 4-6.
* Stata:		All estimations were done with Stata 18. 			
*------------------------------------------------------------------------------*

clear
set more off


*--------------------------------------------------
* Install packages
*--------------------------------------------------
*	for saving results in memory
	ssc install parmest
	
*	for combinign margins plots
	ssc install combomarginsplot

	
*-------------------
* Load data + prepare 
*-------------------
	use "cb_Georgia_data_prep.dta"
	global control1 tbilisi heard_violence harmed econ_cond uni_degree female i.agecat
	global control2 borderinsec tbilisi heard_violence harmed econ_cond uni_degree female i.agecat
	
	
*--------------------------------------------------
* Figure 4. Likelihood of perceiving border as a threat
*--------------------------------------------------
quietly logit borderinsec i.close_01 $control1, cluster(psu)
	
	#delimit ;
	margins close_01, at(
		tbilisi=0 
		harmed=1 
		heard_violence=1 
		agecat=3 
		econ_cond=3 
		female=0 
		uni_degree=0
		) 
	;
	#delimit cr 

	* Plotting the margins 
	#delimit ;
	marginsplot,
			ylabel(.2(.2)0.8, labsize(vsmall) angle(horizontal) grid gstyle(minor))
			ymtick(.2(.1)0.8)
			recast(scatter) xscale(range(0.5 2) extend titlegap(+2))
			leg(off)
			title("")
			xtitle("", size(*.75))
			ytitle("Pr(Border as threat)" , size(small) )
			graphregion(c(white) margin(small))
			plotr(m(large))
			graphregion(margin(large))
			xlabel(0 `" "Outside 0.1°" "border regions" "' 1 `" "Within 0.1°" "SO border region" "' 
			2 `" "Within 0.1°" "AB border region" "', nogrid labsize(small)) 
			ysize(1) xsize(1) 
			plotregion(lcolor(black)) 
			scheme(s2mono)
	; 
	#delimit cr
	graph export "Figure_4.pdf", as(pdf) replace


*--------------------------------------------------
* Figure 5. Support for use of force at SO ABL
*--------------------------------------------------
	# delimit ;
	quietly mlogit border_force 
				i.close_01
				$control2, 
				cluster(psu) l(95) base(2) nolog
	;
	#delimit cr
	
	#delimit ;
	margins close_01, at(
		borderinsec=1
		tbilisi=0 
		harmed=1 
		heard_violence=1 
		agecat=3 
		econ_cond=3 
		female=0 
		uni_degree=0
		) 
	;
	#delimit cr 

	#delimit ;
	marginsplot,
	legend(order( 	4 "Don't agree" 
					5  " Neither"
					6 " Agree")                                                                         
						col(3)
                        size(*.8)                                          
						position(6) ring(12) region(lwidth(none)))
			ylabel(0(.2)1, labsize(small) angle(horizontal) grid gstyle(minor) )
			ymtick(.1(.1)0.9)
			recast(scatter)  xscale(range(-.5 2.5) extend titlegap(+1))
			xdimension(close_01)	
			title("")
			xtitle("", size(*.75))
			ytitle("Pr(Support for use of force)" , size(small) )
			graphregion(c(white) margin(small))
			xlabel(0 `" "Outside 0.1°" "borders" "' 1 `" "Within 0.1°" "SO border" "' 
			2 `" "Within 0.1°" "AB border" "', nogrid labsize(small)) 
			ysize(1) xsize(1) 
			plot1opts(msymbol(T) mcolor(black))
			plotregion(lcolor(black)) 
			scheme(s2mono)
	; 
	#delimit cr		
	graph export "Figure_5.pdf", as(pdf) replace

		
*--------------------------------------------------
* Figure 6. Preferred partner for Georgian armed forces
*--------------------------------------------------
	# delimit ;
	mlogit DV_partner 
				i.close_03
				$control2
				i.europ_values, cluster(psu) l(95) base(2) nolog
	;
	#delimit cr
	estimate store partner_all

	* EUROPEAN VALUES BENEFIT europ_values = 3
	* Predicted margins: outside 0.3 border region
	forvalues x = 1/3  {
		quietly	estimate restore partner_all
			#delimit ;
				margins, at(close_03=0
				borderinsec=0
				harmed=1 
				heard_violence=1 
				agecat=2 
				econ_cond=3 
				female=1 
				uni_degree=0
				tbilisi=0 
				europ_values=3
				) 
			predict(outcome(`x'))		
			contrast
			post
		;
		#delimit cr 
	estimates store partner_all_out_EU_`x'
	parmest, saving("partner_all_out_EU_`x'.dta", replace) level(95) idstr("out_EU_`x'")
	}
	
	* Predicted margins: SO border region
	forvalues x = 1/3  {
		quietly	estimate restore partner_all
			#delimit ;
				margins, at(close_03=1
				borderinsec=0
				harmed=1 
				heard_violence=1 
				agecat=2 
				econ_cond=3 
				female=1 
				uni_degree=0
				tbilisi=0 
				europ_values=3
				) 
			predict(outcome(`x'))		
			contrast
			post
		;
		#delimit cr 
	estimates store partner_all_SO_EU_`x'
	parmest, saving("partner_all_SO_EU_`x'.dta", replace) level(95) idstr("SO_EU_`x'")
	}

	* Predicted margins: AB border region
	forvalues x = 1/3  {
		quietly	estimate restore partner_all
			#delimit ;
				margins, at(close_03=2
				borderinsec=0
				harmed=1 
				heard_violence=1 
				agecat=2 
				econ_cond=3 
				female=1 
				uni_degree=0
				tbilisi=0 
				europ_values=3
				) 
			predict(outcome(`x'))		
			contrast
			post
		;
		#delimit cr 
	estimates store partner_all_AB_EU_`x'
	parmest, saving("partner_all_AB_EU_`x'.dta", replace) level(95) idstr("AB_EU_`x'")
	}

* Plot the predicted probabilities for pro-EU values       
	preserve
               
       * Appending exported datasets with marginal effects 
		clear
		use "partner_all_out_EU_1"
		append using "partner_all_out_EU_2"
		append using "partner_all_out_EU_3"
		append using "partner_all_SO_EU_1"
		append using "partner_all_SO_EU_2"
		append using "partner_all_SO_EU_3"		
		append using "partner_all_AB_EU_1"
		append using "partner_all_AB_EU_2"
		append using "partner_all_AB_EU_3"
		
		gen event = substr(idstr,-1,.)
		destring event, replace
		gen id = "SO_border" if regexm(idstr, "SO")
		replace id = "AB_border" if regexm(idstr, "AB")
		replace id = "out_border" if regexm(idstr, "out")
		keep estimate min* max* id event 
			
		* Figure: Preferred partner       
 		encode id, gen(new_id)

			#delimit ; 	
				twoway scatter estimate new_id if event ==1, msize(*.8) mfcolor(gs0) mlcolor(gs0)
						|| rcap min95 max95 new_id if event == 1, lcolor(gs0) lwidth(*1.15)
				|| scatter estimate new_id if event == 2, msymbol(T) msize(*.8) mfcolor(gs5) mlcolor(gs5)
						|| rcap min95 max95 new_id if event == 2, lcolor(gs5) lwidth(*1.15)
				|| scatter estimate new_id if event == 3, msymbol(D) msize(*.8) mfcolor(gs10) mlcolor(gs10)
						|| rcap min95 max95 new_id if event == 3, lcolor(gs10) lwidth(*1.15)
			xsize(1) ysize(1) 
				xscale(range(.75 3.25) )
                yscale(range())
				ylabel(0(0.2).8 , valuelabel angle(0) labsize(*.80) grid gstyle(minor))
				ymtick(.1(0.1)0.7)
				xlabel(	1 `" "Within 0.3°" "AB border" "' 
						2 `" "Within 0.3°" "SO border" "' 
						3 `" "Outside 0.3°" "borders" "',
						angle(horizontal) nogrid labsize(*.80))
				xtitle("", size(*.75))
				ytitle("Pr(Preferred military partner)", size(*.80))
				legend(order( 	1 "NATO/EU" 3 "Russia" 5 "Don't know")
                                   row(1)
                                   size(*.8)                                          
									keygap(*0.75) 
                                   symxsize(*0.35) 
                                   symysize(*0.5)
								   bm(zero)
                                   region(lcolor(white)) bm(l=12 r=3)
                                   position(6) ring(6) 
                                   )
					title("Pro-European values", size(*.8) color(black))
					plotregion(lcolor(black)) 
                    graphregion(color(white) lcolor(white) lalign(outside))
					scheme(s2mono)
					saving(margins_partner_all_EU, replace)
              ; 
               #delimit cr  	
	graph export "Figure_6_Pro.pdf", replace			

	
* EUROPEAN VALUES NOT COMPATIBLE europ_values = 2	
clear all
	use "cb_Georgia_data_prep.dta"
	global control2 borderinsec tbilisi heard_violence harmed econ_cond uni_degree female i.agecat
				
# delimit ;
	mlogit DV_partner 
				i.close_03
				$control2
				i.europ_values, cluster(psu) l(95) base(2) nolog
	;
	#delimit cr
	estimate store partner_all	
	
	* Predicted margins: outside 0.3 border region
	forvalues x = 1/3  {
		quietly	estimate restore partner_all
			#delimit ;
				margins, at(close_03=0
				borderinsec=0
				harmed=1 
				heard_violence=1 
				agecat=2 
				econ_cond=3 
				female=1 
				uni_degree=0
				tbilisi=0 
				europ_values=2
				) 
			predict(outcome(`x'))		
			contrast
			post
		;
		#delimit cr 
	estimates store partner_all_out_notEU_`x'
	parmest, saving("partner_all_out_notEU_`x'.dta", replace) level(95) idstr("out_notEU_`x'")
	}
	
	* Predicted margins: SO border region
		forvalues x = 1/3  {
		quietly	estimate restore partner_all
			#delimit ;
				margins, at(close_03=1
				borderinsec=0
				harmed=1 
				heard_violence=1 
				agecat=2 
				econ_cond=3 
				female=1 
				uni_degree=0
				tbilisi=0 
				europ_values=2
				) 
			predict(outcome(`x'))		
			contrast
			post
		;
		#delimit cr 
	estimates store partner_all_SO_notEU_`x'
	parmest, saving("partner_all_SO_notEU_`x'.dta", replace) level(95) idstr("SO_notEU_`x'")
	}

	* Predicted margins: AB border region
	forvalues x = 1/3  {
		quietly	estimate restore partner_all
			#delimit ;
				margins, at(close_03=2
				borderinsec=0
				harmed=1 
				heard_violence=1 
				agecat=2 
				econ_cond=3 
				female=1 
				uni_degree=0
				tbilisi=0 
				europ_values=2
				) 
			predict(outcome(`x'))		
			contrast
			post
		;
		#delimit cr 
	estimates store partner_all_AB_notEU_`x'
	parmest, saving("partner_all_AB_notEU_`x'.dta", replace) level(95) idstr("AB_notEU_`x'")
	}

* Plot the predicted probabilities for EU values not compatible      
               
       * Appending exported datasets with marginal effects 
		clear
		use "partner_all_out_notEU_1"
		append using "partner_all_out_notEU_2"
		append using "partner_all_out_notEU_3"
		append using "partner_all_SO_notEU_1"
		append using "partner_all_SO_notEU_2"
		append using "partner_all_SO_notEU_3"		
		append using "partner_all_AB_notEU_1"
		append using "partner_all_AB_notEU_2"
		append using "partner_all_AB_notEU_3"
		
		gen event = substr(idstr,-1,.)
		destring event, replace
		gen id = "SO_border" if regexm(idstr, "SO")
		replace id = "AB_border" if regexm(idstr, "AB")
		replace id = "out_border" if regexm(idstr, "out")
		keep estimate min* max* id event 
			
		* Figure: Preferred partner       
 		encode id, gen(new_id)

			#delimit ; 	
				twoway scatter estimate new_id if event ==1, msize(*.8) mfcolor(gs0) mlcolor(gs0)
						|| rcap min95 max95 new_id if event == 1, lcolor(gs0) lwidth(*1.15)
				|| scatter estimate new_id if event == 2, msymbol(T) msize(*.8) mfcolor(gs5) mlcolor(gs5)
						|| rcap min95 max95 new_id if event == 2, lcolor(gs5) lwidth(*1.15)
				|| scatter estimate new_id if event == 3, msymbol(D) msize(*.8) mfcolor(gs10) mlcolor(gs10)
						|| rcap min95 max95 new_id if event == 3, lcolor(gs10) lwidth(*1.15)
			xsize(1) ysize(1) 
				xscale(range(.75 3.25) )
                yscale(range())
				ylabel(0(0.2).8 , valuelabel angle(0) labsize(*.80) grid gstyle(minor))
				ymtick(.1(0.1)0.7)
				xlabel(	1 `" "Within 0.3°" "AB border" "' 
						2 `" "Within 0.3°" "SO border" "' 
						3 `" "Outside 0.3°" "borders" "',
						angle(horizontal) nogrid labsize(*.80))
				xtitle("", size(*.75))
				ytitle("Pr(Preferred military partner)", size(*.80))
				legend(order( 	1 "NATO/EU" 3 "Russia" 5 "Don't know")
                                   row(1)
                                   size(*.8)                                          
									keygap(*0.75) 
                                   symxsize(*0.35) 
                                   symysize(*0.5)
								   bm(zero)
                                   region(lcolor(white)) bm(l=12 r=3)
                                   position(6) ring(6) 
                                   )
					title("Anti-European values", size(*.8) color(black))
					plotregion(lcolor(black)) 
                    graphregion(color(white) lcolor(white) lalign(outside))
					scheme(s2mono)
					saving(margins_partner_all_notEU, replace)
              ; 
               #delimit cr  	
	graph export "Figure_6_Anti.pdf", replace	

				
* END predicted probability figures
